package tech.xs.common.domain.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import tech.xs.common.framework.domain.annotations.ChildDict;
import tech.xs.common.framework.domain.annotations.ChildDictData;
import tech.xs.common.framework.domain.annotations.Dict;
import tech.xs.common.framework.domain.annotations.DictData;
import tech.xs.common.framework.domain.constant.ModuleNames;
import tech.xs.common.framework.domain.enums.BaseEnum;

import java.util.HashMap;
import java.util.Map;

/**
 * 是否枚举 0:否 1:是
 *
 * @author 沈家文
 * @since 2023/6/21 9:18
 */
@Dict(code = "YesNo", name = "是否", module = ModuleNames.COMMON,
        children = {
                @ChildDict(code = "EnableDisable", name = "启用禁用"),
                @ChildDict(code = "EnableNoEnable", name = "启用未启用"),
                @ChildDict(code = "NormalAnomaly", name = "正常异常"),
                @ChildDict(code = "OnOff", name = "开关"),
        }
)
public enum YesNoEnum implements BaseEnum {

    /**
     * No
     * 禁用
     * 否
     */
    @DictData(name = "否", order = 20,
            children = {
                    @ChildDictData(childCode = "EnableNoEnable", name = "未启用"),
                    @ChildDictData(childCode = "EnableDisable", name = "禁用"),
                    @ChildDictData(childCode = "NormalAnomaly", name = "异常"),
                    @ChildDictData(childCode = "OnOff", name = "关"),
            }
    )
    NO(0),

    /**
     * Yes
     * 启用
     * 是
     */
    @DictData(name = "是", order = 10,
            children = {
                    @ChildDictData(childCode = "EnableNoEnable", name = "启用"),
                    @ChildDictData(childCode = "EnableDisable", name = "启用"),
                    @ChildDictData(childCode = "NormalAnomaly", name = "正常"),
                    @ChildDictData(childCode = "OnOff", name = "开"),
            }
    )
    YES(1);


    @EnumValue
    @JsonValue
    private final int value;

    private static final Map<Integer, YesNoEnum> mappings = new HashMap<>(values().length);

    static {
        for (YesNoEnum item : values()) {
            mappings.put(item.getValue(), item);
        }
    }

    YesNoEnum(int value) {
        this.value = value;
    }

    @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
    public static YesNoEnum create(int value) {
        return mappings.get(value);
    }


    @Override
    public Integer getValue() {
        return value;
    }

}
